<?php use_helper ('Form','DateForm','Object') ?>
<?php echo form_tag('Occupant/add') ?>
<?php use_javascript('jquery-1.3.2.min.js') ?>

<script language="javascript">
var stations = <?php echo json_encode($Station); ?>;
var buildings = <?php echo json_encode($Building); ?>;

var result = {};

function populateArray(rVal)
{
	var plen = jQuery('#building_id')[0].length
	for (var i=0; i<plen; i++)
	{
		jQuery('#building_id')[0][0] = null;
	}
	var count=0;
	jQuery.each(buildings, function(i, val)
	{
	if (val[0] == rVal)
		{
		jQuery('#building_id')[0][count++] = new Option(val[1], i);
		}
	});
} // END populateArray

jQuery(function(){
	populateArray(jQuery("#station_id").val());
	jQuery("#station_id").change(function(){
		populateArray(jQuery("#station_id").val());
	});
}
); //END

</script>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tbody>
		<tr>
			<td colspan="2" nowrap="nowrap">
				<table width="100%" border="0" cellspacing="0" cellpadding="0" class="school_hdng">
					<tr>
					<td><h2>Add Occupant's Information: <span></span></h2></td>
					<td align="right"><h3>&nbsp;</h3></td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td width="461" nowrap="nowrap" class="heading"></td>
			<td width="464"  align="right"></td>
		</tr>
		<tr>
			<td height="20" colspan="2">&nbsp;</td>
		</tr>
	</tbody>
</table>

<table width="100%" align="left" cellpadding="0" cellspacing="0"  border="0" class="form">

<tr>
	<td width="13%">&nbsp;</td>
	<td width="87%">&nbsp; </td>
</tr>
  
 <tr>
    <td height="30">Station:</td>
    <td height="30"> <?php echo object_select_tag('', '', array ( 'name'=>'station_id', 'id'=>'station_id', 'related_class' => 'Station' , 'peer_method' => 'GetStation' ));?></td>
  </tr>
  
  <tr>
  	<td height="30">Building:</td>
	<td height="30"> <?php echo object_select_tag('', '', array ( 'name'=>'building_id', 'id'=>'building_id', 'related_class' => 'Building' , 'peer_method' => 'GetVacantBuilding'));?> </td>
</tr>
  <tr>
    <td height="30">Army No. :</td>
    <td height="30"><?php echo input_tag ('army_no', '','size=38'); ?></td>
  </tr>
  
  <tr>
    <td height="30"=>Rank:</td>
	<td height="30"> <?php echo input_tag('rank', '' ,'size=38') ?></td>
	<script type="text/javascript">
	/*var rank = new LiveValidation('rank', { validMessage: "<?php //echo Constant::VALIDATION_SUCCESS; ?>"});
	rank.add( Validate.Presence,{ failureMessage: "<?php //echo Constant::VALIDATION_REQUIRED_FIELD; ?>"});*/
	</script>
  </tr>
  
  <tr>
    <td height="30">Name:<span class="error"> *</span></td>
	<td height="30"> <?php echo input_tag('name', '' ,'size=38') ?></td>
	<script type="text/javascript">
	var name = new LiveValidation('name', { validMessage: "<?php echo Constant::VALIDATION_SUCCESS; ?>"});
	name.add( Validate.Presence,{ failureMessage: "<?php echo Constant::VALIDATION_REQUIRED_FIELD; ?>"});
	</script>
  </tr>
  
  <tr>
    <td height="30">Unit/Formation:<span class="error"> *</span></td>
	<td height="30"> <?php echo input_tag('unit', '' ,'size=38') ?></td>
	<script type="text/javascript">
	var unit = new LiveValidation('unit', { validMessage: "<?php echo Constant::VALIDATION_SUCCESS; ?>"});
	unit.add( Validate.Presence,{ failureMessage: "<?php echo Constant::VALIDATION_REQUIRED_FIELD; ?>"});
	</script>
  </tr>
  
   <tr>
    <td height="30">Date of Occupation:</td>
	<td height="30"> <?php echo input_date_tag('date_occupied', '' ,'rich=ture') ?></td>
	<script type="text/javascript">
	/*var date_occupied = new LiveValidation('date_occupied', { validMessage: "<?php echo Constant::VALIDATION_SUCCESS; ?>"});
	date_occupied.add( Validate.Presence,{ failureMessage: "<?php echo Constant::VALIDATION_REQUIRED_FIELD; ?>"});*/
	</script>
  </tr>

  
  <tr>
		<td>&nbsp;</td>
		<td colspan="2">
		<table width="100%" align="left" border="0" class="form">
			<tr>
				<td width="2%"><?php echo submit_tag('', array('class'=>'btn_add', 'style'=>'border:none')); ?> </td>
				<td width="98%"><?php echo link_to(' ', (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : 'Home/index', array('class' => 'btn_cancel'));?></td>
			</tr>
    	</table>
		</td>
  </tr>
</table>
